<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>中科小店</title>
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${basepath}/wuliuTemplate/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link rel="stylesheet" href="${basepath}/wuliuTemplate/css/zTreeStyle.css">
</head>
 <style>
  @font-face {
      font-family: "iconfont";
      src: url('fonts/iconfont.eot'); /* IE9*/
      src: url('fonts/iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
      url('fonts/iconfont.woff') format('woff'), /* chrome, firefox */
      url('fonts/iconfont.ttf') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
      url('fonts/iconfont.svg#iconfont') format('svg'); /* iOS 4.1- */
    }
  .iconfont {
      font-family:"iconfont" !important;
      font-size:16px;
      font-style:normal;
      -webkit-font-smoothing: antialiased;
      -webkit-text-stroke-width: 0.2px;
      -moz-osx-font-smoothing: grayscale;
    }
   
    html,body{height:100%;}
    *{margin:0;padding:0;}
    li{list-style:none;}
	a{text-decoration:none!important;cursor:pointer;}
    .show{display:block!important;}
	.panel-show{top:40px!important;}
	
	
	.wrapper{padding:40px 0;}
	.shadow{background:rgba(0,0,0,0.5);z-index:50;height:100%;width:100%;position:absolute;display:none;}
    .model-box{min-height:800px;border:1px solid #ddd;margin:0 auto;padding:20px 30px;}
    .model-box .model-colum{position:relative;padding-left:100px;}
    .model-box .model-name{padding:15px 0 15px 100px;}
    .model-box .model-colum label{font-size:16px;height:30px;line-height:30px;position:absolute;left:0;}
    .model-box .model-colum input{height:30px; text-indent:15px;width:250px;}
    table { width:100%; }
    table tbody tr{ border:1px solid #e7eaec; }
    table tbody tr.title td { height:30px;line-height:30px;background:#f8f8f8;text-align:center;min-width:100px; }
    table tbody tr.detail td { padding:15px; border:1px solid #e7eaec;min-width:100px;}
	table tbody tr.detail td.area-td{overflow:hidden;zoom:1;}
	table tbody tr.detail td.area-td .area{float:left;}
	table tbody tr.detail td.area-td .edit-remove{float:right;}
	table tbody tr.detail td.area-td .edit-remove .delete-btn{margin-left:20px;}
	table tbody tr.detail td.post-td{ text-align:center;}
    table tbody tr.detail td.post-td input{width:60px;text-align:center;text-indent:0;}
    table tbody tr.detail td .new-btn{color:#3879D9;text-decoration:none;outline:none;border:none;}
    .bottom-btn{margin-top:20px;}
	.bottom-btn .btn{padding:5px 30px;border:1px solid #ddd;}
	.bottom-btn .save-btn{background:#3879D9;color:#fff;}
	.bottom-btn .back-btn{margin-left:10px;}
	
    .model-box .model-content .model-right{position:relative;}
    .modal-dialog{min-width:1000px!important;}
    .model-panel{background:#fff;}
    .model-panel .model-header{background:#f8f8f8;overflow:hidden;}
    .model-panel .model-header h5{height:35px;margin:0;line-height:35px;padding:0 15px;font-size:18px;}
    .model-panel .model-footer{background:#f8f8f8;overflow:hidden;height:65px;margin:0;line-height:65px;padding:0 15px;border-top:1px solid #ddd;}
    .model-panel .model-footer .footer-btn{text-align:center;}
    .model-panel .model-footer .footer-btn .btn{padding:5px 30px;border:1px solid #ddd;}
    .model-panel .model-footer .footer-btn .confirm-btn{background:#3879D9;color:#fff;}
    .model-panel .model-footer .footer-btn .cancel-btn{margin-left:10px;}
    .model-panel .model-content{padding:30px 0;}
    .model-panel .model-content .model-middle-box{margin:0 auto;min-width:900px;width:80%;height:450px;}
    .model-panel .model-content .model-middle-box .model-middle-box_a{min-width:225px;width:25%;height:450px;float:left;}
    .model-panel .model-content .model-middle-box .choose_area{border:1px solid #ddd;}
    .model-panel .model-content .model-middle-box .btn_area{text-align:center;}
    .model-panel .model-content .model-middle-box .choosen_area{border:1px solid #ddd;}
    .model-panel .model-content .model-middle-box .btn_area .add-btn,.remove-btn{padding:5px 30px;border:1px solid #ddd;margin-top:200px;}
    .model-panel .model-content .model-middle-box .btn_area p{margin-top:30px;color:#999;}
    .model-panel .model-content .model-middle-box .model-middle-box_a h5{background:#f8f8f8;height:47px;margin:0;line-height:47px;text-align:center;font-size:17px;border-bottom:1px solid #ddd;}
    .model-panel .model-content .model-middle-box #arealist{overflow:auto;height:400px;}
	.model-panel .model-content .model-middle-box #arealist li{line-height:25px;}
	.model-panel .model-content .model-middle-box #arealist li a{line-height:25px;height:25px;text-decoration:none;}
	.model-panel .model-content .model-middle-box #arealist_selected{overflow:auto;height:400px;}
	.model-panel .model-content .model-middle-box #arealist_selected li{line-height:25px;}
	.model-panel .model-content .model-middle-box #arealist_selected li a{line-height:25px;height:25px;text-decoration:none;}
	.button.remove{vertical-align:middle!important;margin-top:-5px!important;margin-left:10px!important;}

    @media screen and (max-width: 1640px){
       .model-panel .model-header h5{height:30px;line-height:30px;}
       .modal-dialog{min-width:940px!important;}
       .model-panel .model-content{padding:20px 0;}
       .model-panel .model-content .model-middle-box{min-width:880px;width:80%;height:400px;}
       .model-panel .model-content .model-middle-box .model-middle-box_a{min-width:220px;height:400px;}
       .model-panel .model-content .model-middle-box #arealist{overflow:auto;height:350px;}
       .model-panel .model-content .model-middle-box #arealist_selected{overflow:auto;height:350px;}
    }
 </style>
    <body>
    <div class="wrapper">
    <input  type="hidden"  id="tem_id"   value="${template_id!}"  >
         <div class="model-box">
             <div class="model-name model-colum">
                 <label>模板名称</label>
                 <div class="model-right"><input class="template_name" type="text" value="${template.template_name!}" placeholder="请输入模板名称" /></div>
             </div>
             <div class="model-content model-colum">
                 <label>配送区域</label>
                 <div class="model-right">
                     <table>
                         <tbody>
                               <tr class="title"><td>可配送区域</td><td>首件</td><td>运费</td><td>续件</td><td>运费</td></tr>
                         </tbody>
                         <tbody class="model-list">
                            
                         </tbody>
                         <tbody>
                            <tr class="detail"><td colspan="5"><a href="javascript:;" class="new-btn" data-toggle="modal" data-target="#jsModal">设置配送区域和运费</td></a></tr>
                         </tbody>
                     </table>
                     
                      <div class="bottom-btn">
                               <a class="save-btn btn">保存</a><a href="javascript:history.back()" class="back-btn btn">返回</a>      
                      </div>
                 
                    
                 </div>
             </div>
         </div>
    </div>
    
         <!-- Modal -->
    <div class="modal fade" id="jsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content model-panel">
                <div class="modal-header model-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h5>选择可配送区域</h5>
                </div>
                <div class="modal-body model-content">
                     <div class="model-middle-box">
                           <div class="model-middle-box_a choose_area">
                                  <h5>可选省、市、区</h5>
                                  <ul id="arealist" class="ztree"></ul>
                           </div>
                           <div class="model-middle-box_a btn_area">
                                  <a class="add-btn btn">添加</a>
                                  <p>请选择可选区域，进行添加操作</p>
                           </div>
                           <div class="model-middle-box_a choosen_area">
                                  <h5>已选省、市、区</h5>
                                  <ul id="arealist_selected" class="ztree"></ul>
                           </div>
                           <div class="model-middle-box_a btn_area">
                                  <a class="remove-btn btn">删除</a>
                                  <p>请选择已选区域，进行删除操作</p>
                           </div>
                     </div>
                </div>
                <div class="modal-footer model-footer" id="modal-footer">
                     <div class="footer-btn">
                          <a class="confirm-btn btn">确定</a><a class="cancel-btn btn">取消</a>      
                     </div>
                </div>
            </div>
        </div>
    </div>
    
    </body>
    <script src="${basepath}/wuliuTemplate/js/jquery.min.js"></script>
    <script src="${basepath}/vendor/js/bootstrap.min.js?v=3.3.6"></script>
    <script type="text/javascript" src="${basepath}/wuliuTemplate/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${basepath}/wuliuTemplate/js/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${basepath}/wuliuTemplate/js/jquery.ztree.exedit.js"></script>
    <script type="text/javascript" src="${basepath}/plugin/layer/layer.js"></script>
 
    <script type="text/javascript">
    
    localdata = {
    		set:function(key,val)
    		{
    			val = (typeof val=="object")?JSON.stringify(val):val;
    			localStorage.setItem(key,val);
    		},
    		get:function(key,datatype)
    		{
    			if( typeof datatype=="undefined" )
    				return localStorage.getItem(key);
    			else
    				return JSON.parse(localStorage.getItem(key));
    		},
    		del:function(key)
    		{
    			localStorage.removeItem(key);
    		},
    		clear:function()
    		{
    			localStorage.clear();
    		}
    	};


    function Console(val)
    {
    	ret = "";
    	
    	if( arguments.length==0 )
    		ret = "未填写参数";
    	else
    		for(i=0;i<arguments.length;i++)
    		{
    			str = arguments[i];
    			ret += (typeof(str)=="object")?JSON.stringify(str):str;
    		}
    	
    	console.log(ret);
    }

    function Alert(val)
    {
    	ret = "";
    	
    	if( arguments.length==0 )
    		ret = "未填写参数";
    	else
    		for(i=0;i<arguments.length;i++)
    		{
    			str = arguments[i];
    			ret += (typeof(str)=="object")?JSON.stringify(str):str;
    		}
    	
    	alert(ret);
    }

   function Ajax(url,data,success,failed)
   {
	// 两种调用方式：
	// GET  -- Ajax(url,success,failed);
	// POST -- Ajax(url,postdata,success,failed);
	
	// 6 中可能的情况：
	// 1,n,n,n
	// 1,2,n,n
	// 1,2,3,n
	// 1,2,3,4
	// 1,n,2,n
	// 1,n,3,4
	
	var param = {};
	param.url = url;
	param.data = "";
	param.type = "get";
	param.success = function(ret){ if(!ret.state) layer.msg(ret.msg); };
	param.failed  = function(ret){
		layer.confirm("网络异常，是否重新加载？",{
			yes:function(){ location.reload(true); },
			cancel:function(){ history.back(); }
		});
	};
	
	switch(arguments.length)
	{
		case 2:
			if( typeof(arguments[1])!="function" )
			{
				param.type = "post";
				param.data = arguments[1];
			}
			else
				param.success = arguments[1];
			break;
		case 3:
			if( typeof(arguments[1])!="function" )
			{
				param.type = "post";
				param.data = arguments[1];
				param.success = arguments[2];
			}
			else
			{
				param.success = arguments[1];
				param.failed  = arguments[2];
			}
			break;
		case 4:
			param.type    = "post";
			param.data    = arguments[1];
			param.success = arguments[2];
			param.failed  = arguments[3];
			break;
	}
	
	// 显示加载提示
	layer.load(1,{shade: [0.5]});
	$.ajax({
		url:param.url,
		type:param.type,
		data:param.data,
		dataType:"json",
		success:function(ret){
			layer.closeAll();
			param.success(ret);
//			Console("Ajax Return : ",ret);
		},
		error:function(ret){
			layer.closeAll();
	    	param.failed(ret);
		}
	});
    
}


//========================================================================================


		<!--
		var setting = {
          check: {
		      enable: true,
		      chkStyle: "checkbox",
		      chkboxType: { "Y": "ps", "N": "ps" },
	        },
			data: {
				simpleData: {
					enable: true
				}
			},
		    view: {
				showIcon: false,
			    showLine: false, 
				},
		};
		
		var setting_selected = {
          check: {
		      enable: true,
		      chkStyle: "checkbox",
		      chkboxType: { "Y": "ps", "N": "ps" },
	        },
			data: {
				simpleData: {
					enable: true
				}
			},
		    view: {
				showIcon: false,
			    showLine: false, 
				},
		};

		
         //初始化
		 var zNodes =[];
         var zNodes_selected=[];
         var delete_id=[];

	     //Ajax请求数据
	      template_id=$("#tem_id").val();
	      url="/system/templateWuliu/ajax_edit?template_id="+template_id;
	      Ajax(url,function(ret){
	    	  
	    	  Console(ret.data.item_list);
	    	  
	    	  zNodes=JSON.parse(ret.data.remain_add_json);  //未选地址
	    	  
 			  item_data=(ret.data).item_list;  
 			  for(i=0;i<item_data.length;i++){
 				  
 				  sku_area_text=item_data[i].sku_area_text;
 				  addrJson=item_data[i].addrJson;
 				  id_array=item_data[i].areas_id_list;
 				  first_num=item_data[i].first_num;
 				  fee=item_data[i].fee;
 				  continue_num=item_data[i].continue_num;
 				  continue_fee=item_data[i].continue_fee;
 				  id=item_data[i].id;
 				  
		          var area_tpl='<p>'+sku_area_text+'</p>'; 
 		          tr_tpl='<tr class="detail">';
 			      tr_tpl+='<td class="area-td"><div class="area">'
 			      tr_tpl+=area_tpl;
 			      tr_tpl+='</div><div class="edit-remove"><a class="edit-btn" data-toggle="modal" data-target="#jsModal">编辑</a><a class="delete-btn">删除</a></div></td>';
 		          tr_tpl+='<td class="post-td"><input class="first_num" type="text" placeholder="1" value="' + first_num + '"/></td>';
		          tr_tpl+='<td class="post-td"><input class="post-fee" type="text" placeholder="0.00" value="' + fee + '"/></td>';
		          tr_tpl+='<td class="post-td"><input class="continue_num" type="text" placeholder="1" value="' + continue_num + '"/></td>';
		          tr_tpl+='<td class="post-td"><input class="continue_fee" type="text" placeholder="0.00" value="' + continue_fee + '"/></td>';  
 			      tr_tpl+="<input type='hidden' class='zNode' data-value='"+ addrJson +"' />";
 			      tr_tpl+="<input type='hidden' class='name_array' data-value='"+ sku_area_text +"' />";
 			      tr_tpl+='<input type="hidden" class="id_array" data-value="'+id_array+'" />';
 			      tr_tpl+='<input type="hidden" class="id" data-value="'+ id +'" />';
 			      tr_tpl+='</tr>';
		          $(".model-list").append(tr_tpl);	 
 			  }
 			  
	      })  

		
		$(document).ready(function(){
			
			//增加模板项 
			
			var new_temp='';
			$(".new-btn").on("click",function(){
				localdata.set("model_item","add")
			    url="/system/templateWuliu/ajax_getAddItemId?template_id="+template_id;
 			    Ajax(url,function(ret){
			        if(ret){
			        	new_temp=ret.data;
				        zNodes_selected=[];
				        var treeObj = $.fn.zTree.getZTreeObj("arealist");
				        $.fn.zTree.init($("#arealist"), setting, zNodes);
				        var treeObj = $.fn.zTree.getZTreeObj("arealist_selected");
				        $.fn.zTree.init($("#arealist_selected"), setting, zNodes_selected);
			        }
 			   })
				
			})
			
			
			$(".cancel-btn").on("click",function(){
				$('#jsModal').modal('hide');
			})
			
			
			$(".add-btn").on("click",function(){  			
				    var j=0,Nodes_delete=[];
				    var zNodes_selected_new=[];
				    var treeObj = $.fn.zTree.getZTreeObj("arealist");
					if(treeObj == null){
						 layer.msg("没有可以选择的区域，请尝试重新加载！");
						 return;
					}
				    var selected_nodes = treeObj.getCheckedNodes(true);
				    
					if(selected_nodes ==''){
						    layer.msg("请选择区域，进行删除操作！");
							return;
					}
					else
					{
						
						// 选中的节点 
				        for(var i=0;i<selected_nodes.length;i++){
				            id=selected_nodes[i].id;
						    pId=selected_nodes[i].pId;
						    name=selected_nodes[i].name;
							zNodes_selected_new[i]={id,pId,name};            //新选择的树节点 ,将要被添加到右侧
							
							// 左侧被全选的节点，将被删除
							if(selected_nodes[i].getCheckStatus().checked==true && selected_nodes[i].getCheckStatus().half==false){
								Nodes_delete[j]=selected_nodes[i];
								j++;
							};
						}
					    
					     
						// 排除重复项（右侧已有节点  zNodes_selected,将被添加的节点zNodes_selected_new）
						zNodes_selected_str = JSON.stringify(zNodes_selected);
						for(i=0;i<zNodes_selected_new.length;i++)
						{
							item = JSON.stringify(zNodes_selected_new[i]);
							if( zNodes_selected_str.indexOf(item)<0 )
							{
								zNodes_selected.push(zNodes_selected_new[i]);
							}
						}
						
						// 右侧加入添加节点,初始化树结构
		      			$.fn.zTree.init($("#arealist_selected"), setting_selected, zNodes_selected);

						
		                // 左侧移除已添加树节点
		                for(var i=0;i<Nodes_delete.length;i++){
						    treeObj.removeNode(Nodes_delete[i]); 
	                    }
		                
		                //更新左侧zNodes节点数组    
 		                var NodesArray = treeObj.transformToArray(treeObj.getNodes());
 		                zNodes=NodesArray;
						for(var i=0;i<zNodes.length;i++){
				              id=zNodes[i].id;
						      pId=zNodes[i].pId;
						      name=zNodes[i].name;
						      zNodes[i]={id,pId,name};     //删除后的zNode节点数组 
						}  

					}
			  })
			  
                    
                //选择节点删除
			    $(".remove-btn").on("click",function(){
			    	  var j=0,Nodes_delete=[];
				      var zNodes_selected_right_new=[];
				      var treeObj = $.fn.zTree.getZTreeObj("arealist_selected");
					  if(treeObj == null){
						   layer.msg("没有可以删除的区域，请先添加可选区域！");
						   return;
					  }
					
				      selected_nodes_right = treeObj.getCheckedNodes(true);
					  if(selected_nodes_right ==''){
						   layer.msg("请选择已选区域，进行删除操作！");
						   return;
					  }
					  else{
						  
						  //选中的节点
						  for(var i=0;i<selected_nodes_right.length;i++){
				              id=selected_nodes_right[i].id;
						      pId=selected_nodes_right[i].pId;
						      name=selected_nodes_right[i].name;
							  zNodes_selected_right_new[i]={id,pId,name};     //右侧新选择的树节点,将被添加到左侧
	
							  
							  // 被全选的节点,将被删除的节点
							  if(selected_nodes_right[i].getCheckStatus().checked==true && selected_nodes_right[i].getCheckStatus().half==false){
									Nodes_delete[j]=selected_nodes_right[i];
									j++;
							  };
			  	  
					         }
							 
						  
							 // 排除重复项  已有节点zNodes,将添加的节点
							 zNodes_str = JSON.stringify(zNodes);
							 for(i=0;i<zNodes_selected_right_new.length;i++)
							 {
								 item = JSON.stringify(zNodes_selected_right_new[i]);
								 if( zNodes_str.indexOf(item)<0 )
								 {
										zNodes.unshift(zNodes_selected_right_new[i]);
								 }
							 }
					
						     // 左侧加入添加节点,更新树结构
			      		     $.fn.zTree.init($("#arealist"), setting_selected, zNodes);
						   
			                 // 右侧移除已添加树节点,
			                 for(var i=0;i<Nodes_delete.length;i++){
							    treeObj.removeNode(Nodes_delete[i]);
		                     }
			                 
				             //更新右侧zNodes_selected节点数组    
		 		             var NodesArray = treeObj.transformToArray(treeObj.getNodes());
		 		             zNodes_selected=NodesArray;
							 for(var i=0;i<zNodes_selected.length;i++){
						            id=zNodes_selected[i].id;
								    pId=zNodes_selected[i].pId;
								    name=zNodes_selected[i].name;
								    zNodes_selected[i]={id,pId,name};     //删除后的zNodes_selected节点数组
								    
								
							}  

					  }

				})
				
				var name_array=[];
				var words_array=[];
				var id_array=[];
				
				
				$(".confirm-btn").on("click",function(){
					name_array=[];
					words_array=[];
					id_array=[];
					if(zNodes_selected.length==0){
						 layer.msg("请选择区域！");
						 return;
					}
					else{
					    var treeObj = $.fn.zTree.getZTreeObj("arealist_selected");
	 		            var NodesArray = treeObj.transformToArray(treeObj.getNodes());
						for(var i=0;i<NodesArray.length;i++){
							 name_array.push(NodesArray[i].name); 
							 if(NodesArray[i].isParent==false){
								 id_array.push(NodesArray[i].id);
							 }
							 
						 }

			             //3层循环
 			             var NodesArray = treeObj.getNodes();
 	 		             for(var i=0;i<NodesArray.length;i++){
 	 		            	words_array[i]={}
 	 		            	words_array[i].children=[];
 	 		            	words_array[i].name=NodesArray[i].name;
	 		            	for(var j=0;j<NodesArray[i].children.length;j++){
	 		            		(words_array[i].children)[j]=[];
	 		            		(words_array[i].children)[j]=(NodesArray[i].children)[j].name;
/* 	 		            		for(var m=0;m<(NodesArray[i].children)[j].children.length;m++){
	 	 		            		 (name_array[i].children)[j].children=[];
	 		            			((name_array[i].children)[j].children)[m]=1;
	 		           
	 		            		} */
	 		            	}
	 		               
	 		              }  
	 		              
			             id=new_temp;
 	 		             
			             var area_tpl='';
 		                 for(var i=0;i<words_array.length;i++){
 	 		            	 area_tpl+='<p>'+words_array[i].name+'('+ words_array[i].children+')'+'</p>'
 	 		             } 
 		                 
 		                 
			             if(localdata.get("model_item")=="edit"){
			            	 
                             elm=$(".model-list tr.edit");
			            	 elm.find(".area").html(area_tpl);
			            	 elm.find(".zNode").data("value",JSON.stringify(zNodes_selected));
			            	 elm.find(".name_array").data("value",area_tpl);
			            	 
			            	 //Alert(id_array);
			            	 id_array_str=id_array.join(",");
			            	 elm.find(".id_array").data("value",id_array_str);
			            	 
			            	 $('#jsModal').modal('hide');
	 	 					 
			             }else{
 		                 
 	 		             tr_tpl='<tr class="detail">';
 	 		             tr_tpl+='<td class="area-td"><div class="area">'
 	 		             tr_tpl+=area_tpl;
 	 		             tr_tpl+='</div><div class="edit-remove"><a class="edit-btn" data-toggle="modal" data-target="#jsModal" >编辑</a><a class="delete-btn">删除</a></div></td>';
 	 	 		         tr_tpl+='<td class="post-td"><input class="first_num" type="text" placeholder="1" value="1"/></td>';
 	 			         tr_tpl+='<td class="post-td"><input class="post-fee" type="text" placeholder="0.00" value="0.00"/></td>';
 	 			         tr_tpl+='<td class="post-td"><input class="continue_num" type="text" placeholder="1" value="1"/></td>';
 	 			         tr_tpl+='<td class="post-td"><input class="continue_fee" type="text" placeholder="0.00" value="0.00"/></td>';  
 	 		             tr_tpl+="<input type='hidden' class='zNode' data-value='"+JSON.stringify(zNodes_selected)+"' />";
 	 		             tr_tpl+="<input type='hidden' class='name_array' data-value='"+area_tpl+"' />";
 	 		             tr_tpl+='<input type="hidden" class="id_array" data-value="'+id_array+'" />';
 	 		             tr_tpl+='<input type="hidden" class="id" data-value="'+ id +'" />';
 	 		             tr_tpl+='</tr>';
 	 		           
 	 		             
 	 		             $(".model-list").append(tr_tpl);		             
 	 		             $('#jsModal').modal('hide');
 	 		             
			             }
			             
 	 					 new_temp='';
 	 		             
 	 		             
					}

					
				})
				
				//================编辑删除列表项=================//
				$(".model-list").on("click",".edit-btn",function(){
					localdata.set("model_item","edit");
				    elm=$(this).parents("tr");
				    $(".model-list tr").removeClass("edit");
				    elm.addClass("edit");
				    
				    zNodes_selected=elm.find(".zNode").data("value");
				    
				    if(typeof(zNodes_selected)=='string'){
				    	zNodes_selected=JSON.parse(zNodes_selected);
				    };
				    
					
					//左侧初始化
					var treeObj = $.fn.zTree.getZTreeObj("arealist");
					$.fn.zTree.init($("#arealist"), setting, zNodes);
					
					// 右侧初始化
					var treeObj = $.fn.zTree.getZTreeObj("arealist_selected");
	      			$.fn.zTree.init($("#arealist_selected"), setting_selected, zNodes_selected);
					
				})
				
				
				$(".model-list").on("click",".delete-btn",function(){
				    elm=$(this).parents("tr");
				    zNodes_selected=elm.find(".zNode").data("value");
					
					layer.confirm("确定要删除吗？",function(){		    
					    //已选中的，将被删除,节点将被添加到右侧节点数组
						for(var i=0;i<zNodes_selected.length;i++){
							zNodes.unshift(zNodes_selected[i]);
						}  

					    
						//左侧初始化
						var treeObj = $.fn.zTree.getZTreeObj("arealist");
						$.fn.zTree.init($("#arealist"), setting, zNodes);
					    elm.remove();
						layer.msg('成功删除！');
						
						//删除项的id,用于提交
						delete_id.push(elm.find(".id").data("value"));
						
					})
					
				})
				
				
				//控制文本输入	
			    $(".model-list").on("keyup",".first_num",function(){
                    elm=$(this);
                    num=$(this).val();
                    $(this).val(num.replace(/[^\d]/g,''));
			     })
			     
			    $(".model-list").on("keyup",".continue_num",function(){
                    elm=$(this);
                    num=$(this).val();
                    $(this).val(num.replace(/[^\d]/g,''));
			    })
			    
			    $(".model-list").on("keyup",".post-fee",function(){
                    elm=$(this);
                    num=$(this).val();
                    $(this).val(num.replace(/[^\d.]/g,''));
			     })
			     
			    $(".model-list").on("keyup",".continue_fee",function(){
                    elm=$(this);
                    num=$(this).val();
                    $(this).val(num.replace(/[^\d.]/g,''));
			     })
			     
			    $(".model-list").on("blur",".post-fee",function(){
			    	elm=$(this);
                    num=Number($(this).val());
                    $(this).val(num.toFixed(2));
			     })
			     
			     
			    $(".model-list").on("blur",".continue_fee",function(){
                    elm=$(this);
                    num=Number($(this).val());
                    $(this).val(num.toFixed(2));
			    })
			
				
				
				//================保存提交数据====================
				$(".save-btn").on("click",function(){
					
					elm=$(".template_name");
					val=elm.val();
					if(val==""){
						layer.msg("请输入模板名称！");
						elm.focus();
						return;
					}
				    
				    data={template_id:"",item:"",remainJson:""};
				
				    data.template_id=template_id;        
				    data.remainJson=zNodes;         //未选择的区域对应的节点
				    
				    data.item=[];
				    elms = $(".model-list tr");
				    for(i=0;i<elms.length;i++)
				    {
				    	item = {};
				    	item.jsonString = elms.eq(i).find(".zNode").data("value");
				    	item.skuString = elms.eq(i).find(".name_array").data("value");
				    	item.idString = elms.eq(i).find(".id_array").data("value");
				    	item.item_id=elms.eq(i).find(".id").data("value");
				    	
				    	item.first_num = elms.eq(i).find(".first_num").val();
				    	item.fee = elms.eq(i).find(".post-fee").val();
				    	item.continue_num = elms.eq(i).find(".continue_num").val();
				    	item.continue_fee = elms.eq(i).find(".continue_fee").val();
				    	
				    	data.item.push(item);
				    }

				    template_name=$(".template_name").val();

				    delete_id_str=delete_id.join(",");
				    
				    //Console(data);
			        //Ajax提交数据
				    url="/system/templateWuliu/editTemplate";
			        
    			    Ajax(url,{"data":JSON.stringify(data),"template_name":template_name,"delete_id":delete_id_str},function(ret){
    			    	if(ret.state==true){
				    		  layer.msg("保存成功！");
				    	 };
				    })
					
				})

				
		});
		//-->
	</script>
</body>


</html>